package kn.tool.md5;

import cn.hutool.crypto.SecureUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.DigestUtils;

import java.math.BigInteger;

/**
 * @author: dengkunnan
 * @date: 2020-07-12 17:58
 * @description:Description: md5工具类
 **/
public class Md5Util {
    /**
     * 返回字符传的MD5值
     *
     * @param content
     * @return
     */
    public static String getStrTomd5(String content) {
        if (StringUtils.isEmpty(content)) {
            return "";
        }

        return SecureUtil.md5(content);
    }


    /**
     * 返回字符传的MD5值
     *
     * @param content
     * @return
     */
    public static String getMd5Length32(String content) {

        byte[] secretBytes = null;
        secretBytes = DigestUtils.md5Digest(content.getBytes());
        String md5code = new BigInteger(1, secretBytes).toString(16);
        for (int i = 0; i < 32 - md5code.length(); i++) {
            md5code = "0" + md5code;
        }
        return md5code;
    }
}
